<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遍历</title>
    <script src="./js/jquery-3.6.0.js"></script>
    <style>
        div{
            width: 100px;
            height: 100px;
            border: 1px solid #e1e1e1;
        }
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <script>
        $(function() {
            // 将上面的每个盒子分别设置一个背景色
            let colorArr = ['red', 'green', 'blue'];
            // $('div').each(function(index, ele) {
            //     $(ele).css('background-color', colorArr[index % 3]);
            // })
            $.each($('div'), function(index, ele) {
                $(ele).css('background-color', colorArr[index % 3]);
            });

            $.each(colorArr, function(i, e) {
                console.log(i);
                console.log(e);
            });

            $.each({'name': 'andy', age: 19}, function(i, e) {
                console.log(i); // 属性名
                console.log(e); // 属性值
            })
        })
        

    </script>
</body>
</html>